package date1127.container;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.lu.jdog.util.Resource;

import date1127.container.event.BaseEvent;
import date1127.container.event.EmailEvent;
import date1127.container.listener.EmailNotifier;

public class SpringTest {
	private static ApplicationContext applicationContext;

	public static void main(String[] args) {

		String beadPath = Resource.getAssertPath(SpringTest.class, "beans.xml");
		System.out.println(Resource.getAssertPath(EmailNotifier.class));
		applicationContext = new ClassPathXmlApplicationContext(beadPath);

		// 创建一个 ApplicationEvent 对象
		EmailEvent ele = new EmailEvent("hello", "spring@test.com", "this is a test");
		// 发出事件
		applicationContext.publishEvent(ele);
		
//		没有日志，接收不到，BaseEvent 未继承自ApplicationEvent
//		而一个bean想发布事件，则可以实现ApplicationContextAware 或 BeanFactoryAware接口，获取到容器，使用context发布。 
		BaseEvent baseEvent = new BaseEvent("baseEvent","基本消息");
		applicationContext.publishEvent(baseEvent);
		
		
	}
}
